package com.hjy.search.controller;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.hjy.common.to.es.SkuEsModel;
import com.hjy.common.utils.R;
import com.hjy.search.service.ElasticSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RequestMapping("/search")
@RestController
public class ElasticSearchController {
    @Autowired
    private ElasticSearchService elasticSearchService;

    @RequestMapping("/saveskus")
    public R saveSkuProducts(@RequestBody List<SkuEsModel> list) throws IOException {
        Boolean flag = elasticSearchService.saveSkuProducts(list);

        // 如果出错, 为 true
        if (flag) {
            return R.error();
        }else {
            return R.ok();
        }
    }
}
